import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    redirect: '/panoramicHall' // 将根路径重定向到名为 'home' 的组件
  },
  {
    path: '/panoramicHall',
    name: 'PanoramicHall',
    component: resolve => require(['@/views/panoramicHall'], resolve),
    meta: {
      title: '全景大厅'
    }
  },
  {
    path: '/facialRegistration',
    component: Layout,
    children: [{
      path: '/facialRegistration',
      name: 'FacialRegistration',
      component: resolve => require(['@/views/facialRegistration'], resolve),
      meta: {
        title: '人脸注册'
      }
    }]
  },
  {
    path: '/facialMaintenance',
    component: Layout,
    children: [{
      path: '/facialMaintenance',
      name: 'FacialMaintenance',
      component: resolve => require(['@/views/facialMaintenance'], resolve),
      meta: {
        title: '人脸数据维护'
      }
    }]
  },
  {
    path: '/warningMonitoring',
    component: Layout,
    children: [{
      path: '/warningMonitoring',
      name: 'WarningMonitoring',
      component: resolve => require(['@/views/warningMonitoring'], resolve),
      meta: {
        title: '预警监控'
      }
    }]
  },
  {
    path: '/personalProfile',
    component: Layout,
    children: [{
      path: '/personalProfile',
      name: 'PersonalProfile',
      component: resolve => require(['@/views/personalProfile'], resolve),
      meta: {
        title: '个人档案'
      }
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
